package com.penjin.android.activity.secretary;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.penjin.android.R;
import com.penjin.android.activity.apply.MyApplyDetailActivity;
import com.penjin.android.activity.kaoqin.GerenKaoqinActivity;
import com.penjin.android.domain.JPushData;
import com.penjin.android.receiver.JPushConstants;
import com.penjin.android.service.UserService;
import com.penjin.android.view.TitleBarView;

/**
 * Created by lxl on 2016/3/12.
 */
public class SecretaryDetailsActivity extends Activity implements View.OnClickListener{

    TitleBarView titleBarView;
    //news
    private ImageView newsIcon ;
    private TextView newsContent ;
    private TextView newsNum ;

    //paper check
    private ImageView paperCheckIcon ;
    private TextView paperCheckMan ;
    private TextView paperCheckKind ;
    private TextView paperCheckTime ;
    private TextView paperCheckNum ;

    //kaoqin
    private ImageView kaoqinIcon ;
    private TextView kaoqinMan ;
    private TextView kaoqinKind ;
    private TextView kaoqinTime ;
    private TextView kaoqinNum ;

    //kaoqin result
    private ImageView kaoqinResultIcon ;
    private TextView kaoqinResultMan ;
    private TextView kaoqinResultKind ;
    private TextView kaoqinResultTime ;
    private TextView kaoqinResultNum ;


    //view
    View secretaryNnews ;
    View secretaryPaper ;
    View secretaryKaoqinRemind ;
    View secretaryKaoqinResult ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_secretary_details);

        initView();

    }

    @Override
    protected void onResume() {
        super.onResume();
        setContent();
        setNums();
    }

    private void initView(){

        titleBarView= (TitleBarView) findViewById(R.id.titleBarView);
        titleBarView.setTitleBarListener(new TitleBarView.TitleBarListener() {
            @Override
            public void left(View view) {
                finish();
            }

            @Override
            public void center(View view) {

            }

            @Override
            public void right(View view) {

            }
        });
        //news
        newsIcon = (ImageView) findViewById(R.id.item_secretary_news_icon);
        newsContent = (TextView) findViewById(R.id.item_secretary_news_content);
        newsNum = (TextView)findViewById(R.id.item_secretary_details_news_num)  ;

        //paper check
        paperCheckIcon = (ImageView) findViewById(R.id.item_secretary_paper_check_icon);
        paperCheckMan = (TextView) findViewById(R.id.item_secretary_paper_check_man_edit);
        paperCheckKind = (TextView) findViewById(R.id.item_secretary_paper_check_kind_edit);
        paperCheckTime = (TextView) findViewById(R.id.item_secretary_paper_check_time_edit);
        paperCheckNum = (TextView)findViewById(R.id.item_secretary_details_paper_num);

        //kaoqin
        kaoqinIcon = (ImageView) findViewById(R.id.item_secretary_kaoqin_icon);
        kaoqinMan = (TextView) findViewById(R.id.item_secretary_kaoqin_man_edit);
        kaoqinKind = (TextView) findViewById(R.id.item_secretary_kaoqin_kind_edit);
        kaoqinTime = (TextView) findViewById(R.id.item_secretary_kaoqin_time_edit);
        kaoqinNum =  (TextView)findViewById(R.id.item_secretary_details_kaoqin_num);

        //kaoqin result
        kaoqinResultIcon = (ImageView) findViewById(R.id.item_secretary_kaoqin_result_icon);
        kaoqinResultMan = (TextView) findViewById(R.id.item_secretary_kaoqin_man_result_edit);
        kaoqinResultKind = (TextView) findViewById(R.id.item_secretary_kaoqin_result_kind_edit);
        kaoqinResultTime = (TextView) findViewById(R.id.item_secretary_kaoqin_result_time_edit);
        kaoqinResultNum = (TextView) findViewById(R.id.item_secretary_details_kaoqin_result_num);


        secretaryNnews = findViewById(R.id.item_secretary_news) ;
        secretaryPaper = findViewById(R.id.item_secretary_paper) ;
        secretaryKaoqinRemind = findViewById(R.id.item_secretary_kaoqin_remind) ;
        secretaryKaoqinResult = findViewById(R.id.item_secretary_result_kaoqin) ;

        secretaryNnews.setOnClickListener(this);
        secretaryPaper.setOnClickListener(this);
        secretaryKaoqinRemind.setOnClickListener(this);
        secretaryKaoqinResult.setOnClickListener(this);

        setContent() ;
        setNums();


    }

    @Override
    public void onClick(View v) {

        Intent intent ;

        switch (v.getId()){

            case R.id.item_secretary_news:

                UserService.getInstance(this).setSecretaryNum(JPushConstants.NEWS,0);
                intent = new Intent(this,SecretaryNewsListActivity.class) ;
                startActivity(intent);

                break;
            case R.id.item_secretary_paper:

                UserService.getInstance(this).setSecretaryNum(JPushConstants.PAPER_CHECK,0);
                intent = new Intent(this, MyApplyDetailActivity.class);
                intent.putExtra("type", 0);
                startActivity(intent);

                break;
            case R.id.item_secretary_kaoqin_remind:

                UserService.getInstance(this).setSecretaryNum(JPushConstants.KAOQIN,0);
                intent = new Intent(SecretaryDetailsActivity.this, GerenKaoqinActivity.class);
                startActivity(intent);

                break;
            case R.id.item_secretary_result_kaoqin:

                UserService.getInstance(this).setSecretaryNum(JPushConstants.KAOQIN_RESULT,0);
                intent = new Intent(SecretaryDetailsActivity.this,GerenKaoqinActivity.class) ;
                startActivity(intent);

            default:


        }
    }

    private void setNums(){


        int newsNums = UserService.getInstance(this).getSecretaryNum(JPushConstants.NEWS) ;
        int paperCheckNums = UserService.getInstance(this).getSecretaryNum(JPushConstants.PAPER_CHECK) ;
        int kaoqinNums = UserService.getInstance(this).getSecretaryNum(JPushConstants.KAOQIN) ;
        int kaoqinResultNums = UserService.getInstance(this).getSecretaryNum(JPushConstants.KAOQIN_RESULT) ;


        if( newsNums != 0 ){

            newsNum.setVisibility(View.VISIBLE);
            newsNum.setText(String.valueOf(newsNums));

        }else {

            newsNum.setVisibility(View.INVISIBLE);

        }
        if( paperCheckNums != 0 ){

            paperCheckNum.setVisibility(View.VISIBLE);
            paperCheckNum.setText(String.valueOf(paperCheckNums));

        }else {

            paperCheckNum.setVisibility(View.INVISIBLE);

        }
        if( kaoqinNums != 0 ){

            kaoqinNum.setVisibility(View.VISIBLE);
            kaoqinNum.setText(String.valueOf(kaoqinNums));

        }else {

            kaoqinNum.setVisibility(View.INVISIBLE);

        }
        if( kaoqinResultNums != 0 ){

            kaoqinResultNum.setVisibility(View.VISIBLE);
            kaoqinResultNum.setText(String.valueOf(kaoqinResultNums));

        }else {

            kaoqinResultNum.setVisibility(View.INVISIBLE);

        }

    }

    private void setContent(){

        JPushData secretaryNewsData = UserService.getInstance(this).getNewPush(JPushConstants.NEWS) ;
        JPushData secretaryPaperData = UserService.getInstance(this).getNewPush(JPushConstants.PAPER_CHECK) ;
        JPushData secretaryKaoqinRemindData = UserService.getInstance(this).getNewPush(JPushConstants.KAOQIN) ;
        JPushData secretaryKaoqinResultData = UserService.getInstance(this).getNewPush(JPushConstants.KAOQIN_RESULT) ;



        if( secretaryNewsData.getMessage() != null ){

            secretaryNnews.setVisibility(View.VISIBLE);
            newsContent.setText(secretaryNewsData.getMessage());

        }
        if(secretaryPaperData.getMessage()!= null){

            secretaryPaper.setVisibility(View.VISIBLE);
            paperCheckKind.setText(secretaryPaperData.getMessageTitle());
            paperCheckMan.setText(secretaryPaperData.getMessage());

        }
        if( secretaryKaoqinRemindData.getMessage()!=null){

            secretaryKaoqinRemind.setVisibility(View.VISIBLE);
            kaoqinKind.setText(secretaryKaoqinRemindData.getMessageTitle());
            kaoqinMan.setText(secretaryKaoqinRemindData.getMessage());

        }
        if( secretaryKaoqinResultData.getMessage() !=null){

            secretaryKaoqinResult.setVisibility(View.VISIBLE);
            kaoqinResultKind.setText(secretaryKaoqinResultData.getMessageTitle());
            kaoqinResultMan.setText(secretaryKaoqinResultData.getMessage());

        }


    }

}
